package com.elong.qadev.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import com.elong.qadev.tool.AESUtils;
import com.elong.qadev.tool.MD5Utils;
@Entity
@Table(name = "HTTP_HEADER", schema = "ti")
public class Header {
	
	private int id;
	private int CaseId;
    private String key;
    private String value;
    private String encryption;
    private String secret;
    private String doc;
    private String comments;
    
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "ID", unique = true, nullable = false, length = 10)
    public int getId() {
    	return id;
    }
    
    public void setId(int id) {
    	this.id = id;
    }
    
	@Column(name = "CASEID", nullable = false, length = 50)
	public int getCaseId() {
		return CaseId;
	}

	public void setCaseId(int caseId) {
		CaseId = caseId;
	}

	public Header() {
		super();
    }
	 public Header(int id, String key, String value, String encryption, String secret, String doc, String comments,
			int caseId) {
		super();
		this.id = id;
		this.key = key;
		this.value = value;
		this.encryption = encryption;
		this.secret = secret;
		this.doc = doc;
		this.comments = comments;
		CaseId = caseId;
	}

	@Column(name = "HEADER_KEY",nullable = true, length = 50)
    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }
    @Column(name = "HEADER_VALUE",nullable = true, length = 100)
    public String getValue() {
    	 if ("NONE".equals(encryption)) {
             return value;
         } else if ("AES".equals(encryption)) {
             return AESUtils.encryptByKey(value, secret);
         } else if ("MD5".equals(encryption)) {
             return MD5Utils.encrypt(value);
         } else {
             return value;
         }
    }

    public void setValue(String value) {
        this.value = value;
    }
    
    @Column(name = "ENCRYPTION",nullable = true, length = 50)
    public String getEncryption() {
        return encryption;
    }

    public void setEncryption(String encryption) {
        this.encryption = encryption;
    }
    @Column(name = "HEADER_SECRET",nullable = true, length = 50)
    public String getSecret() {
        return secret;
    }

    public void setSecret(String secret) {
        this.secret = secret;
    }
    @Column(name = "DOC",nullable = true, length = 100)
    public void setDoc(String doc) {
        this.doc = doc;
    }

    public String getDoc() {
        return doc;
    }
    @Column(name = "COMMENTS",nullable = true, length = 100)
    public String getComments() {
        return comments;
    }

    public void setComments(String comments) {
        this.comments = comments;
    }

	@Override
	public String toString() {
		return "Header [id=" + id + ", CaseId=" + CaseId + ", key=" + key
				+ ", value=" + value + ", encryption=" + encryption
				+ ", secret=" + secret + ", doc=" + doc + ", comments="
				+ comments + "]";
	}
}
